/*
 * Copyright (C) 2011 Project R'yleh Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.Arkham;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

public class ItemDetails extends Activity  implements OnClickListener{
	
	TextView name, price;
    Item item = new Item();
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
	    Intent i = getIntent();
	    item = (Item) i.getParcelableExtra("item");
	    item.setModifiers((Stats) i.getParcelableExtra("itemStats"));
		
		//removes title bar and sets the theme
        this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        
		super.onCreate(savedInstanceState);
		setContentView(R.layout.itemview);
		
		name = (TextView) findViewById(R.id.itemName);
		name.setText(item.getName());
		price = (TextView) findViewById(R.id.purchasePrice);
		price.setText("Price: $" + item.getPurchasePrice() + "\n");
		
	    GridView gridviewStats = (GridView) findViewById(R.id.itemDetailGrid);
	    gridviewStats.setAdapter(new ItemAdapter(this));
        
	}
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
	
	public class ItemAdapter extends BaseAdapter {
		private Context context;
		private String[] texts = {
		 "Strength: ", "+" + Integer.toString(item.getStrengthModifier()), 
		 "Attack: ", "+" + Integer.toString(item.getAttackPowerModifier()),
		 "Agility: ", "+" + Integer.toString(item.getAgilityModifier()),
		 "Hit%: ", "+" + Integer.toString(item.getHitPercentageModifier()),
		 "Vitality: ", "+" + Integer.toString(item.getVitalityModifier()),
		 "Defense: ", "+" + Integer.toString(item.getDefenseModifier()),
		 "Magic: ", "+" + Integer.toString(item.getMagicModifier()),
		 "Evade: ", "+" + Integer.toString(item.getEvadeModifier()),
		 "Magic Defense: ", "+" + Integer.toString(item.getMagicDefenseModifier()),
		 "Magic Evade: ", "+" + Integer.toString(item.getMagicEvadeModifier())
		 };
		
		
		public ItemAdapter(Context context) {
		    this.context = context;
		}

		public int getCount() {
		    return texts.length;
		}

		public Object getItem(int position) {
		    return null;
		}

		public long getItemId(int position) {
		    return 0;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
		    TextView tv;
		    if (convertView == null) {
		        tv = new TextView(context);
		        tv.setLayoutParams(new GridView.LayoutParams(85, 50));
		    }
		    else {
		        tv = (TextView) convertView;
		    }
		    tv.setText(texts[position]);
		    return tv;
		}

	}
}